package com.study.manage.dal;

import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.study.manage.domain.BlogRank;
import com.study.manage.domain.enumm.LiveDieState;

public interface BlogRankRepository extends PagingAndSortingRepository<BlogRank, Long> {

    @Query("select t from BlogRank t,EvaluateApply ea,User u where ea.id=t.evaluateApplyId and ea.userId=u.id and t.evaluateId in (:evaluateId)"
            + " and (ea.number=:number or :number is null) and (ea.userId=:userId or :userId is null)"
            + " and (ea.fullName like %:fullName% or :fullName is null) and (ea.referenceId=:referenceId or :referenceId is null)"
            + " and t.state=:state and (to_days(t.uploadAt) >= to_days(:beginAt) or :beginAt is null)"
            + " and (to_days(t.uploadAt) <= to_days(:endAt) or :endAt is null)"
            + " and (:member is null or u.member>=:member)")
    Page<BlogRank> findByEvaluateIdInAndState(@Param("evaluateId") List<Long> evaluateIds,
            @Param("state") LiveDieState state, @Param("number") String number,
            @Param("userId") Long userId, @Param("fullName") String fullName,
            @Param("referenceId") Long referenceId, @Param("beginAt") Date beginAt,
            @Param("endAt") Date endAt, @Param("member") Integer member, Pageable pageable);


}
